package com.example.fs;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import com.outstanding.framework.base.fs.FileSystemOperation;
import com.outstanding.framework.core.PendingException;

public class FileSystemDemo {
	public static void main(String[] args) throws IOException, PendingException {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
				"spring/framework-plugin-fileSystemBeans.xml");
		context.start();
		FileSystemOperation bean = context.getBean(FileSystemOperation.class);
		Resource resource = new ClassPathResource("conf/prop.key");
		InputStream inputStream = resource.getInputStream();
		ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
		byte[] bs = new byte[1024];
		int length = -1;
		while ((length = inputStream.read(bs)) != -1) {
			byteOut.write(bs, 0, length);
		}
		byte[] byteArray = byteOut.toByteArray();
		String uploadFile = bean.uploadFile(byteArray);
		System.out.println(uploadFile);
		System.out.println(Arrays.toString(byteArray));
		byte[] downloadFile = bean.downloadFile(uploadFile);
		System.out.println(Arrays.toString(downloadFile));
	}
}
